package com.yunhe.abnormal.repository.base;

import com.yunhe.abnormal.domain.base.AlarmRuleInstance;
import org.springframework.data.neo4j.annotation.Query;
import org.springframework.data.neo4j.repository.Neo4jRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface AlarmRuleInstanceRepository extends Neo4jRepository<AlarmRuleInstance, Long> {
    @Query("match p=(a:AlarmRuleInstance)-[:ALARM_RULE_OF]->(b:AlarmRule) where ID(a) in {ids} return p")
    List<AlarmRuleInstance> findByIds(@Param("ids") List<Long> ids);

    @Query("match p=(a:AlarmRuleInstance)-[:ALARM_RULE_OF]->(b:AlarmRule) where a.stationId={stationId} return p")
    List<AlarmRuleInstance> findByStationId(@Param("stationId") Long stationId);

    @Query("match(s:Station{code:{stationCode}}) with ID(s) as stationId " +
            "match(a:AlarmRuleInstance) where a.stationId=stationId return max(a.virtualPointId)")
    Long getMaxAlarmVirtualPid(@Param("stationCode") Long stationCode);

    @Query("match(a:AlarmRuleInstance) where a.virtualPointId in {virtualPids} return a")
    List<AlarmRuleInstance> findByVirtualPointIds(@Param("virtualPids") List<Long> virtualPids);
}
